<template>
  <div class="source-card-wrapper">
    <div class="source-intro">
      <div class="pub-info">
        <span>{{ source.authorName }}</span>
        <span style="color: var(--gray)">|</span>
        {{ new Date(source.publishDate).toLocaleString() }}
      </div>
      <h3 class="source-title">
        {{ source.title }}
      </h3>
      <h3 class="source-abstract">
        {{ source.digest }}
      </h3>
    </div>

    <div class="source-main">
      <img :src="fileIcon" alt="pdf" />
      <a class="hover"></a>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { getFileIcon } from '@/utils/img'
import { open } from '@/utils/link'
import { computed } from 'vue'

const props = defineProps<{
  source: App.Source
}>()

const fileIcon = computed(() => {
  return getFileIcon(props.source.name)
})

function gotoSource() {
  open(`/source/${props.source.id}`)
}

function gotoAuthor() {
  open(`/author/${props.source.authorId}/profile/source`)
}
</script>

<style lang="scss" scoped>
.source-card-wrapper {
  --scw: var(--sourceCardWidth);
  --sch: var(--sourceCardHeight);
  box-sizing: border-box;
  width: var(--scw);
  height: var(--sch);
  padding: calc(var(--sch) * 0.1) calc(var(--scw) * 0.04);

  .source-intro {
    float: left;
    width: 60%;
    text-align: left;
    pointer-events: none;

    .pub-info {
      font-size: calc(var(--sch) * 0.09);
      line-height: 2;
    }

    .source-title {
      font-size: calc(var(--sch) * 0.11);
      font-weight: bold;
      color: var(--dark);
      line-height: 2;
      margin-bottom: calc(var(--sch) * 0.05);
    }

    .source-abstract {
      font-size: calc(var(--sch) * 0.09);
      color: var(--dark);
      line-height: 1.5;
      display: -webkit-box;
      overflow: hidden;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
    }
  }

  .source-main {
    float: right;
    margin-right: 3%;
    height: 100%;
    padding: 0 5px;
    display: flex;
    justify-content: center;
    align-items: center;

    &:hover {
      cursor: pointer;

      .hover {
        display: block;
      }
    }

    img {
      height: 90%;
    }

    .hover {
      display: none;
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      border-radius: 5px;
      background-color: var(--light);
    }
  }
}
</style>
